home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 031a / adg_1_3.zip / SUPERCLS.C < prev    next >
C/C++ Source or Header  |  1991-02-21  |  6KB  |  154 lines

  1. /****************************************************************************
  2. Module name: SuperCls.C
  3. Programmer : Jeffrey M. Richter.
  4. *****************************************************************************/
  5.  
  6. #include "..\nowindws.h"
  7. #undef NOUSER
  8. #undef NOWINOFFSETS
  9. #include <windows.h>
  10.  
  11. #include "supercls.h"
  12.  
  13. // Offsets of base class values from the high-end of the class extra bytes.
  14. #define BCWNDPROCINDEX     (sizeof(FARPROC))
  15. #define CBBCCLSEXTRAINDEX  (sizeof(FARPROC) + sizeof(int))
  16. #define CBBCWNDEXTRAINDEX  (sizeof(FARPROC) + sizeof(int) + sizeof(int))
  17.  
  18. #define MINCBCLSADDTIONAL  (sizeof(FARPROC) + sizeof(int) + sizeof(int))
  19.  
  20. static LONG (FAR PASCAL *_lpfnBCWndProc)();
  21. static int _cbBCClsExtra, _cbBCWndExtra;
  22.  
  23. BOOL FAR PASCAL RegisterSuperClass (LPWNDCLASS WndClass,
  24.                      LONG (FAR PASCAL *lpfnSCWndProc)(),
  25.                      int cbClsAdditional, int cbWndAdditional) {
  26.    HWND hWnd;
  27.    _lpfnBCWndProc = WndClass->lpfnWndProc;
  28.    _cbBCClsExtra  = WndClass->cbClsExtra;
  29.    _cbBCWndExtra  = WndClass->cbWndExtra;
  30.  
  31.    WndClass->cbClsExtra += cbClsAdditional + MINCBCLSADDTIONAL;
  32.    WndClass->cbWndExtra += cbWndAdditional;
  33.    WndClass->lpfnWndProc = lpfnSCWndProc;
  34.    if (!RegisterClass(WndClass)) return(FALSE);
  35.    hWnd = CreateWindow(WndClass->lpszClassName, "", 0, 0, 0, 0, 0,
  36.       NULL, NULL, WndClass->hInstance, 0);
  37.  
  38.    if (hWnd == NULL) {
  39.       UnregisterClass(WndClass->lpszClassName, WndClass->hInstance);
  40.       return(FALSE);
  41.    }
  42.  
  43.    DestroyWindow(hWnd);
  44.    return(TRUE);
  45. }
  46.  
  47. void FAR PASCAL SetSuperClassInfo (HWND hWnd) {
  48.    WORD cbClsTotal = GetClassWord(hWnd, GCW_CBCLSEXTRA);
  49.    DWORD dwBCWndProc = GetWindowLong(hWnd, cbClsTotal - BCWNDPROCINDEX);
  50.    if (dwBCWndProc != NULL) return;
  51.    SetClassLong(hWnd, cbClsTotal - BCWNDPROCINDEX, (LONG) _lpfnBCWndProc);
  52.    SetClassWord(hWnd, cbClsTotal - CBBCCLSEXTRAINDEX, _cbBCClsExtra);
  53.    SetClassWord(hWnd, cbClsTotal - CBBCWNDEXTRAINDEX, _cbBCWndExtra);
  54. }
  55.  
  56.  
  57. DWORD FAR PASCAL GetBCWndProc (HWND hWnd) {
  58.    DWORD dwBCWndProc;
  59.    int nIndex = GetClassWord(hWnd, GCW_CBCLSEXTRA) - BCWNDPROCINDEX;
  60.    dwBCWndProc = GetClassLong(hWnd, nIndex);
  61.    if (dwBCWndProc != NULL) return(dwBCWndProc);
  62.    return((DWORD) _lpfnBCWndProc);
  63. }
  64.  
  65. //****************************************************************************
  66.  
  67. // Function used internally by the Get/SetClassWord/Long functions.
  68. static int NEAR PASCAL CalcClassByteIndex (HWND hWnd, int nIndex) {
  69.    int cbBCClsExtraIndex, cbBCClsExtra;
  70.  
  71.    // if nIndex is negative, nIndex points to internal window memory block,
  72.    // same index should be returned.
  73.    if (nIndex < 0) return(nIndex);
  74.  
  75.    // Retrieve index into class extra bytes for the number of class 
  76.    // extra bytes used by the base class.
  77.    cbBCClsExtraIndex =
  78.       GetClassWord(hWnd, GCW_CBCLSEXTRA) - CBBCCLSEXTRAINDEX;
  79.  
  80.    // Retrieve number of class extra bytes used by the base class.
  81.    cbBCClsExtra = GetClassWord(hWnd, cbBCClsExtraIndex);
  82.  
  83.    // Return desired index + number of class extra bytes used by base class.
  84.    return(nIndex + cbBCClsExtra);
  85. }
  86.  
  87.  
  88.  
  89. // Function used internally by the Get/SetWindowWord/Long functions.
  90. static int NEAR PASCAL CalcWindowByteIndex (HWND hWnd, int nIndex) {
  91.    int cbBCWndExtraIndex, cbBCWndExtra;
  92.  
  93.    // if nIndex is negative, nIndex points to internal window memory block,
  94.    // same index should be returned.
  95.    if (nIndex < 0) return(nIndex);
  96.  
  97.    // Retrieve index into class extra bytes for the number of window
  98.    // extra bytes used by the base class.
  99.    cbBCWndExtraIndex =
  100.       GetClassWord(hWnd, GCW_CBCLSEXTRA) - CBBCWNDEXTRAINDEX;
  101.  
  102.    // Retrieve number of window extra bytes used by the base class.
  103.    cbBCWndExtra = GetClassWord(hWnd, cbBCWndExtraIndex);
  104.  
  105.    // Return desired index + number of window extra bytes used by base class.
  106.    return(nIndex + cbBCWndExtra);
  107. }
  108.  
  109. //****************************************************************************
  110. // The four Get/SetClassWord/Long functions.
  111.  
  112. WORD FAR PASCAL SetSCClassWord (HWND hWnd, int nIndex, WORD wNewWord) {
  113.    nIndex = CalcClassByteIndex(hWnd, nIndex);
  114.    return(SetClassWord(hWnd, nIndex, wNewWord));
  115. }
  116.  
  117. WORD FAR PASCAL GetSCClassWord (HWND hWnd, int nIndex) {
  118.    nIndex = CalcClassByteIndex(hWnd, nIndex);
  119.    return(GetClassWord(hWnd, nIndex));
  120. }
  121.  
  122. DWORD FAR PASCAL SetSCClassLong (HWND hWnd, int nIndex, DWORD dwNewLong) {
  123.    nIndex = CalcClassByteIndex(hWnd, nIndex);
  124.    return(SetClassLong(hWnd, nIndex, dwNewLong));
  125. }
  126.  
  127. DWORD FAR PASCAL GetSCClassLong (HWND hWnd, int nIndex) {
  128.    nIndex = CalcClassByteIndex(hWnd, nIndex);
  129.    return(GetClassLong(hWnd, nIndex));
  130. }
  131.  
  132. //****************************************************************************
  133. // The four Get/SetWindowWord/Long functions.
  134.  
  135. WORD FAR PASCAL SetSCWindowWord (HWND hWnd, int nIndex, WORD wNewWord) {
  136.    nIndex = CalcWindowByteIndex(hWnd, nIndex);
  137.    return(SetWindowWord(hWnd, nIndex, wNewWord));
  138. }
  139.  
  140. WORD FAR PASCAL GetSCWindowWord (HWND hWnd, int nIndex) {
  141.    nIndex = CalcWindowByteIndex(hWnd, nIndex);
  142.    return(GetWindowWord(hWnd, nIndex));
  143. }
  144.  
  145. DWORD FAR PASCAL SetSCWindowLong (HWND hWnd, int nIndex, DWORD dwNewLong) {
  146.    nIndex = CalcWindowByteIndex(hWnd, nIndex);
  147.    return(SetWindowLong(hWnd, nIndex, dwNewLong));
  148. }
  149.  
  150. DWORD FAR PASCAL GetSCWindowLong (HWND hWnd, int nIndex) {
  151.    nIndex = CalcWindowByteIndex(hWnd, nIndex);
  152.    return(GetWindowLong(hWnd, nIndex));
  153. }
  154.